package com.github.thinwonton.excel2sql.sevice;

import cn.hutool.setting.dialect.Props;
import com.github.thinwonton.excel2sql.conf.GenerateProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

public class ReadConfiguration {

    private static final Logger LOGGER = LoggerFactory.getLogger(ReadConfiguration.class);

    /**
     * 要读取的配置文件名称
     */
    public static final String CON_NAME = "config.properties";

    private GenerateProperties generateProperties;

    public ReadConfiguration() {
        String confPath = ReadConfiguration.class.getClassLoader().getResource(CON_NAME).toString();
        File confFile = new File(confPath);

        LOGGER.info("初始化配置：" + confFile.getPath());

        Props props = new Props(confFile.getPath(), "utf-8");

        generateProperties = new GenerateProperties();
        generateProperties.setExcelPath(props.getStr("excelPath"));
        generateProperties.setExportSqlDir(props.getStr("exportSqlDir"));
        generateProperties.setBeginIndex(props.getInt("startIndex"));
        generateProperties.setEndIndex(props.getInt("endIndex"));
        generateProperties.setScriptPerFile(props.getBool("scriptPerFile"));
        generateProperties.setDropSQL(props.getBool("dropSQL"));
    }

    public GenerateProperties getGenerateProperties() {
        return generateProperties;
    }
}
